package com.baihan.angus.app.game.busshow.pop_dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.baihan.angus.app.game.basic.utils.AppUtil;
import com.baihan.angus.app.game.busshow.R;
import com.zzhoujay.richtext.RichText;

public class BgStoryDialog extends Dialog {

    private Context mContext;
    private WindowManager.LayoutParams mLayoutParams;
    private TextView tvStory;
    private ImageView ivClose;
    private LinearLayout llClose;

    public BgStoryDialog(@NonNull Context context) {
        super(context, R.style.FullDialog);
        this.mContext = context;
        initContentView();
        init(context);
        RichText.initCacheDir(context);
    }

    private void init(Context context) {
        this.mContext = context;
        Window dialogWindow = this.getWindow();
        mLayoutParams = dialogWindow.getAttributes();
        mLayoutParams.width = AppUtil.getScreenWidth(context);
        dialogWindow.setAttributes(mLayoutParams);
        dialogWindow.getDecorView().setPadding(0, 0, 0, 0);
        dialogWindow.getDecorView().setBackgroundResource(android.R.color.transparent);
        dialogWindow.setGravity(Gravity.TOP);
    }

    private void initContentView() {
        View dialogView = LayoutInflater.from(this.getContext()).inflate(R.layout.dialog_bg_story, (ViewGroup) null);
        setContentView(dialogView);
        tvStory = dialogView.findViewById(R.id.tvStory);
        ivClose = dialogView.findViewById(R.id.ivClose);
        llClose = dialogView.findViewById(R.id.llClose);

        llClose.setOnClickListener(v -> {
            RichText.clear(this);
            cancel();
        });

    }

    public void initData(String bgStory) {
        tvStory.setText("");
        RichText.from(bgStory).bind(mContext).into(tvStory);
    }
}
